package com.gj.planclass.mapper;


import com.gj.planclass.model.PlanClassServiceVo;
import com.gj.planclass.model.PlanClassVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by Tangyunhen on 2021-06-27.
 */
@Mapper
public interface PlanClassMapper {

    List<PlanClassVo> queryData(PlanClassServiceVo planClassServiceVo);

    int queryCount(PlanClassServiceVo planClassServiceVo);

    @Select("select count(id) from planclass where name=#{name}")
    int queryByName(@NotBlank(message = "名称不能为空") String name);

    @Select("select * from planclass where code=#{code}")
    PlanClassVo queryCode(@NotNull(message = "编码不能为空") String code);

    @Insert("insert into planclass(name,code,remark,status) values (#{name},#{code},#{remark},#{status})")
    void insert(@Valid PlanClassVo PlanClassVo);

    @Select("select * from planclass where id=#{id}")
    PlanClassVo queryById(@NotNull(message = "id不能为空") Integer id);

    @Update("update planclass set name=#{name},remark=#{remark},code =#{code} where id =#{id}")
    void update(@Valid PlanClassVo PlanClassVo);

    @Update("update planclass set status=#{status} where id=#{id}")
    void updateStatus(@Valid PlanClassVo planClassVo);
}
